package com.rtx.edi.gatway.listener.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.rtx.common.EdiConstant;
import com.rtx.edi.gatway.cache.EdiApiDataContext;
import com.rtx.edi.gatway.handle.GatWayHandle;
import com.rtx.edi.gatway.handle.impl.GatWayHandleDefaultImpl;
import com.rtx.edi.gatway.listener.EdiListener;


@Component
public class SkuAfterHandle extends GatWayHandleDefaultImpl implements EdiListener{
	
	@Autowired
	GatWayHandle gatWayHandle;

	@Override
	public void doCustom(EdiApiDataContext apiDataContext) {
		String subDatasourcekeyList = apiDataContext.getApiGlobalMap().get(EdiConstant.ACTIVE_SUB_DATASOURCEKEY_LIST)+"";
		if(!StringUtils.hasLength(subDatasourcekeyList)) {
			return;
		}
		
		for(String whseid:subDatasourcekeyList.split(",")) {
			apiDataContext.getApiGlobalMap().put(EdiConstant.ACTIVE_MAIN_DATASOURCEKEY, whseid);
			
			this.determineWhseidSaveOrUpdate(apiDataContext);
			
			if(EdiConstant.ACTIVE_SAVE.equals(apiDataContext.getDetermineSaveOrUpdate())) {
				this.executerSave(apiDataContext);
			}else if(EdiConstant.ACTIVE_UPDATE.equals(apiDataContext.getDetermineSaveOrUpdate())) {
				this.executerUpdate(apiDataContext);
			}else {
				//报错
				throw new RuntimeException("判断当前下发数据更新或者新增失败!");
			}
		}
	}

}
